﻿<%@ WebHandler Language="C#" Class="detail" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections;

public class detail : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        var xxx=HttpContext.Current.Request.Form["paramJson"];
        JObject jo = (JObject)JsonConvert.DeserializeObject(xxx);
        int gid =Convert.ToInt16(jo["gid"]);


        if (string.IsNullOrEmpty(xxx))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "商品详情";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {

            var x = bll.S_Goods.FirstOrDefault(p => p.GID == gid && p.IsLock!= true);

            if (x != null)
            {
                var GetImgs =  methods.GetImgs(x.GImg);


                //新建一个JArray对象，可以理解成json对象中 value 位置的数组对象 ->  []


                // var gg = bll.S_Store.FirstOrDefault(p => p.SID ==x.s);//全部.ToList();

                //  var GetGimg = _rky.getFirstImgByimg(gg.Simg);
                // var store = new
                //{
                //        Name = gg.Sname,
                //        id = gg.SID,
                //        pic = GetGimg,
                //        slat = gg.Slatitude,
                //        slong = gg.Slongitude,
                //        numb = 0


                //};


                ArrayList sku_price = new ArrayList();

                var sku = new
                {
                    id=gid,
                    goods_id=gid,
                    price=x.GPrice,
                    goods_sku_text="",
                    status="up",
                    weigh=x.GWeight,
                    image=GetImgs[0],
                    stock=x.GCounts,
                    sales=x.GSales,
                    sn=""

                };

                sku_price.Add(sku);


                Uri uri = HttpContext.Current.Request.Url;
                String host = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
                var data = new
                {
                    is_sku=0,
                    sku_price,
                    stock=x.GCounts,   //库存
                    id = x.GID,
                    title=x.GName,
                    content =x.GContent.Replace("src=\"/upload/","src=\""+host+"/upload/"),
                    lname = x.GName,
                    x.SCCLASSID,
                    images=GetImgs,
                    image =GetImgs[0].ToString().Replace("Up","upload"),
                    original_price= x.GPriceYJ,
                    price = x.GPrice2,
                    sales= x.GSales,
                    x.GSort,
                    x.G_Introduce,
                    x.GPrice
                   // store
                };

                context.Response.Write(JsonConvert.SerializeObject(new { code,msg,time,data}));
            }
        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");

    }





    public bool IsReusable {
        get {
            return false;
        }
    }

}